/*
 * @Author: 卡卡 1071780426@qq.com
 * @Date: 2022-08-17 17:24:07
 * @LastEditors: 卡卡 1071780426@qq.com
 * @LastEditTime: 2023-12-27 10:54:57
 * @FilePath: \backstage\src\api\index.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
//通用方法，不带token
import axios from "axios";
const reqNull = (method, url, params) => {
  return axios({
    method: method,
    url: url,
    headers: {
      'Content-Type': 'application/json',
      // 'Content-Security-Policy': 'upgrade-insecure-requests'
    },
    data: params
  }).then(res => res.data);
};


//from-data  形式传参
const reqNullS = (method, url, params) => {
  return axios({
    method: method,
    url: url,
    headers: {
      "content-type": "multipart/form-data",//from-data 形式传参
    },
    data: params
  }).then(res => res.data);
};
// 带请求头

//通用方法，不带token---成都接口重新加headers
const reqNullH = (method, url, params, data) => {
  return axios({
    method: method,
    url: url,
    headers: {
      'Content-Type': 'application/json',
      // 'Content-Security-Policy': 'upgrade-insecure-requests'
      Authorization: data,
    },
    data: params
  }).then(res => res.data);
};

// 通用公用方法
const req = (method, url, params) => {
  // if(Router.currentRoute.path!="/first/first" && Router.currentRoute.path!="/center/myCenter"){
  //     store.commit("showLoading");
  // }
  return axios({
    method: method,
    url: url,
    headers: {
      'Content-Type': 'application/json',
      Authorization: `Bearer ${sessionStorage.getItem('token')}`
    },
    data: params
  }).then(res => {
    // store.commit("hideLoading");
    if (Number(res.data.errcode) == Number(403)) {
      //   Toast.fail({
      //       message: res.data.msg,
      //       onClose: () => {
      //           localStorage.clear();
      //           sessionStorage.clear();
      //           Router.push({ path: "/" });
      //       }
      //   })
    } else if (Number(res.data.errcode) == Number(405)) {

      //   Dialog.confirm({
      //       title: '提示',
      //       message: '您还没有提交认证，请认证',
      //       confirmButtonText: '去认证',
      //       cancelButtonText: '取消',
      //   })
      //   .then(() => {
      //       if(localStorage.getItem("loginType")==0){
      //           // Router.push({path:"/personConfirm"})
      //       }else{
      //           // Router.push({path:"/companyConfirm"})
      //       }
      //   }).catch(err=>{})
    } else if (res.data.errcode == -1) {
      // this.$message.error(res.data.msg);
      //   Toast('您已提交认证，请耐心等待审核');
    } else if (res.data.errcode == -3) {
      //   Dialog.confirm({
      //       title: '提示',
      //       message: '您认证未通过，请重新提交认证',
      //   })
      //   .then(() => {

      //       if(localStorage.getItem("loginType")==0){
      //           Router.push({path:"/personConfirm"})
      //       }else{
      //           Router.push({path:"/companyConfirm"})
      //       }
      //   }).catch(err=>{})

    } else {

      let resData = res.data;
      return resData;
    }
  }).catch(error => {
    console.log(error)
    // store.commit("hideLoading");

  });
};

const up = (method, url, params) => {
  // if(Router.currentRoute.path!="/first/first" && Router.currentRoute.path!="/center/myCenter"){
  //     store.commit("showLoading");
  // }
  return axios({
    method: method,
    url: url,
    headers: {
      'Content-Type': 'multipart/form-data',
      Authorization: `Bearer ${sessionStorage.getItem('token')}`
    },
    data: params
  }).then(res => {
    // store.commit("hideLoading");
    if (Number(res.data.errcode) == Number(403)) {
      //   Toast.fail({
      //       message: res.data.msg,
      //       onClose: () => {
      //           localStorage.clear();
      //           sessionStorage.clear();
      //           Router.push({ path: "/" });
      //       }
      //   })
    } else if (Number(res.data.errcode) == Number(405)) {

      //   Dialog.confirm({
      //       title: '提示',
      //       message: '您还没有提交认证，请认证',
      //       confirmButtonText: '去认证',
      //       cancelButtonText: '取消',
      //   })
      //   .then(() => {
      //       if(localStorage.getItem("loginType")==0){
      //           // Router.push({path:"/personConfirm"})
      //       }else{
      //           // Router.push({path:"/companyConfirm"})
      //       }
      //   }).catch(err=>{})
    } else if (res.data.errcode == -2) {
      //   Toast('您已提交认证，请耐心等待审核');
    } else if (res.data.errcode == -3) {
      //   Dialog.confirm({
      //       title: '提示',
      //       message: '您认证未通过，请重新提交认证',
      //   })
      //   .then(() => {

      //       if(localStorage.getItem("loginType")==0){
      //           Router.push({path:"/personConfirm"})
      //       }else{
      //           Router.push({path:"/companyConfirm"})
      //       }
      //   }).catch(err=>{})

    } else {

      let resData = res.data;
      return resData;
    }
  }).catch(error => {
    console.log(error)
    // store.commit("hideLoading");

  });
};
export {
  req,
  reqNull,
  reqNullS,
  reqNullH,
  up
}